from typing import Optional
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy_crud_plus import CRUDPlus

from modules.project.models.project_model import Project
from modules.project.schemas.project_schema import ProjectCreate, ProjectUpdate
from modules.project.params.project_params import ProjectQuery


class ProjectRepository(CRUDPlus[Project]):

    async def get_by_id(self, db: AsyncSession, pk: int):
        return await self.select_model_by_column(db, id=pk)

    async def create(self, db: AsyncSession, data: ProjectCreate) -> Project:
        return await self.create_model(db, data)

    async def update(self, db: AsyncSession, pk: int, data: ProjectUpdate) -> Optional[Project]:
        await self.update_model(db, pk, data)
        return await self.select_model(db, pk)

    async def delete(self, db: AsyncSession, pk: int) -> bool:
        return await self.delete_model(db, pk)


project_dao = ProjectRepository(Project)